package com.hj.mp.demo.controller;


import com.hj.mp.demo.common.RestfulResponse;
import com.hj.mp.demo.entity.OwnUser;
import com.hj.mp.demo.service.IOwnUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-04-01
 */
@RestController
@RequestMapping("/com/ownUser")
@Api(value = "用户的增删改查")
public class OwnUserController {

//    @Resource
//    private IService iService;
//
//    @RequestMapping("/insert")
//    public RestfulResponse insert(@RequestBody OwnUser ownUser){
//        return RestfulResponse.build(iService.save(ownUser));
//    }
    @Autowired
    private IOwnUserService iOwnUserService;

    @PostMapping("/insert")
    @ApiOperation(value = "新增用户", notes="返回是否操作成功")
    public RestfulResponse insert(@RequestBody OwnUser ownUser){
        return RestfulResponse.build(iOwnUserService.insert(ownUser));
    }

    @DeleteMapping("/del")
    @ApiOperation(value = "通过id删除用户信息", notes="返回删除是否操作成功")
    public RestfulResponse del(@Param("id")String id){
        return RestfulResponse.build(iOwnUserService.del(id));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改用户", notes="返回修改是否操作成功")
    public RestfulResponse update(@RequestBody OwnUser ownUser){
        return RestfulResponse.build(iOwnUserService.update(ownUser));
    }

    @GetMapping("/selectById")
    @ApiOperation(value = "通过用户id获取用户信息", notes="返回用户信息")
    public RestfulResponse selectById(@Param("id")String id){
        return RestfulResponse.build(iOwnUserService.selectById(id));
    }

    @GetMapping("/queryList")
    @ApiOperation(value = "获取用户列表")
    public RestfulResponse queryList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "2") int pageSize){
        return RestfulResponse.build(iOwnUserService.queryList(pageNum,pageSize));
    }
}
